﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ch04
{
    class Class9
    {
        static void Main(string[] args)
        {
            string jx;

            //创建一个可以生成随机数的对象
            Random rand = new Random();
            //使用随机数对象的Next方法生成随机数
            //Console.WriteLine(rand.Next(1,4));

            //与电脑玩石头剪刀布的游戏

            string[] s = { "", "石头", "剪刀", "布" };

            Console.WriteLine("******************");
            Console.WriteLine("     1、石头");
            Console.WriteLine("     2、剪刀");
            Console.WriteLine("     3、布");
            Console.WriteLine("******************");

            do
            {
                Console.Write("请选择你要出的拳：");
                int u = int.Parse(Console.ReadLine());
                //电脑随机生成一个出拳
                int c = rand.Next(1, 4);

                Console.WriteLine("你出{0},电脑玩家出{1}", s[u], s[c]);

                if (u == c)//平局
                {
                    Console.WriteLine("打成平局！");
                }
                else if (c - u == 1 || c - u == -2)
                {
                    Console.WriteLine("恭喜你，你赢了！");
                }
                else
                {
                    Console.WriteLine("很遗憾，你输了！");
                }
                Console.Write("是否继续？(Y/N):");
                jx = Console.ReadLine();

            } while (jx == "Y");
        }
    }
}
